package com.ubirouting;

import com.city.parking.R;
import com.city.parking.util.SharePrefUtil;
import com.ubirouting.ubimaplib.UbiMapView;
import com.ubirouting.ubimaplib.data.UbiMapDownloader;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;


public class IndoorMapActivity extends Activity {

	UbiMapView mMap;
	
	String buildingJson;
//	private VShiTuMapView mapView;
//	private VShiTuMap mShituMap;

	private RelativeLayout areasLayout;
	private TextView coreTextViewAreaName;
	private TextView coreTextViewAreaFloor;
	private TextView coreTextViewDetails;
	private LinearLayout naviLayout;
	private Button coreBtnNaviStart, coreBtnNaviEnd;
	private ImageButton btnZoomOut, btnZoomIn, btnPosition;
	private Button btnClearPath;
	private Button btnChangeFloor;
	private ListView coreFloorSwitch;
//	private VBuilding currentBuilding;
//	private VBasicUnit selectedArea = null;

	private EditText searchBox;
	private Button searchConfirm, searchClean;
	private String searchContent;
	private int searchResultId = -1;
	
	private boolean saved = false;
	private int mall, start, end;

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_indoor_map);
		
		Intent i = this.getIntent();
		long mapId = i.getLongExtra("mapId", -1);
		initView(mapId);


		
//		currentBuilding = ParkingApp.get().mIndoorMapEnginee.getBuilding();
//		initView();
//		mapView.setMapData(currentBuilding);
//
//		mShituMap = mapView.getMap();
//		mShituMap
//				.setOnVShiTuMapClickedListener(new VShiTuMapClickedInterface() {
//
//					@Override
//					public void onBlankClicked() {
//						selectedArea = null;
//						areasLayout.setVisibility(View.GONE);
//						naviLayout.setVisibility(View.GONE);
//					}
//
//					@Override
//					public void onAreaClicked(VBasicUnit unit) {
//						selectedArea = unit;
//						coreTextViewAreaName.setText(unit.name);
//						coreTextViewAreaFloor.setText(unit.floor + "");
//						areasLayout.setVisibility(View.VISIBLE);
//						naviLayout.setVisibility(View.VISIBLE);
//					}
//				});

		searchBox = (EditText) findViewById(R.id.searchBox);
		searchConfirm = (Button) findViewById(R.id.searchConfirm);
		searchClean = (Button) findViewById(R.id.searchClean);
//		searchClean.setOnClickListener(myClickedListener);
//		searchConfirm.setOnClickListener(myClickedListener);
		
		int floor = SharePrefUtil.getFloor();
		start = SharePrefUtil.getIndoorStart();
		end = SharePrefUtil.getIndoorEnd();
		if (start >= 0 && end >= 0) {
//			mShituMap.switchFloor(floor, VShiTuMap.MapRefreshType.Auto);
//			mShituMap.markNaviStartPosition(start);
//			mShituMap.markNaviEndPosition(end);
//			mShituMap.setSpecificAreaColor(start);
//			mShituMap.setSpecificAreaColor(end);
		}
	}
	
	private void initView(long mapId) {
		mMap = (UbiMapView) findViewById(R.id.mapview);
		mMap.load(mapId);
		
		areasLayout = (RelativeLayout) findViewById(R.id.coreAreaInfoLayout);
		coreTextViewAreaName = (TextView) findViewById(R.id.coreTextViewAreaName);
		coreTextViewAreaFloor = (TextView) findViewById(R.id.coreTextViewAreaFloor);
		coreTextViewDetails = (TextView) findViewById(R.id.coreTextViewDetails);
		coreTextViewDetails.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

			}
		});
		naviLayout = (LinearLayout) findViewById(R.id.naviLayout);
		coreBtnNaviStart = (Button) findViewById(R.id.coreBtnNaviStart);
		coreBtnNaviEnd = (Button) findViewById(R.id.coreBtnNaviEnd);
		btnZoomOut = (ImageButton) findViewById(R.id.btnZoomOut);
		btnZoomIn = (ImageButton) findViewById(R.id.btnZoomIn);
		btnPosition = (ImageButton) findViewById(R.id.btnPosition);
		btnClearPath = (Button) findViewById(R.id.btnClearpath);
		btnChangeFloor = (Button) findViewById(R.id.btnChangefloor);
//		coreFloorSwitch = (ListView) findViewById(R.id.coreFloorSwitch);
//		ArrayAdapter<String> floorSwitchAdapter = new ArrayAdapter<String>(
//				getApplicationContext(), R.layout.my_floor_text, mMap.get
//				currentBuilding.getAllFloorNames());
//		coreFloorSwitch.setAdapter(floorSwitchAdapter);
//
//		coreFloorSwitch.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> parent, View view,
//					int position, long id) {
//				mShituMap.switchFloor(
//						currentBuilding.getFloorNumFromIndex(position),
//						MapRefreshType.Manual);
//			}
//		});

//		coreBtnNaviStart.setOnClickListener(myClickedListener);
//		coreBtnNaviEnd.setOnClickListener(myClickedListener);
//		btnChangeFloor.setOnClickListener(myClickedListener);
//		btnPosition.setOnClickListener(myClickedListener);
//		btnZoomOut.setOnClickListener(myClickedListener);
//		btnZoomIn.setOnClickListener(myClickedListener);
//		btnClearPath.setOnClickListener(myClickedListener);
	}


}
